<template>
  <div class="sort">
    <div>
      <div class="title">
        <ul class="all">
          <li
            :class="{ active: selectedLabel.styleId == -1 }"
            data-key="styleId"
            data-value="-1"
            @click="changeSelectedLabel($event)"
          >
            全部
          </li>
          <li
            :class="{ active: selectedLabel.styleId == item1.id }"
            v-for="(item1, index) in sortList.styles"
            :key="index"
            data-key="styleId"
            :data-value="item1.id"
            @click="changeSelectedLabel($event)"
          >
            {{ item1.name }}
          </li>
        </ul>
        <ul class="serials">
          <li
            :class="{ active: selectedLabel.areaId == -1 }"
            data-key="areaId"
            data-value="-1"
            @click="changeSelectedLabel($event)"
          >
            全部
          </li>
          <li
            :class="{ active: selectedLabel.areaId == item2.id }"
            v-for="(item2, index) in sortList.areas"
            data-key="areaId"
            :data-value="item2.id"
            :key="index"
            @click="changeSelectedLabel($event)"
          >
            {{ item2.name }}
          </li>
        </ul>
        <ul class="new">
          <li
            :class="{ active: selectedLabel.isFinish == -1 }"
            data-key="isFinish"
            data-value="-1"
            @click="changeSelectedLabel($event)"
          >
            全部
          </li>
          <li
            :class="{ active: selectedLabel.isFinish == item3.id }"
            v-for="(item3, index) in sortList.status"
            data-key="isFinish"
            :data-value="item3.id"
            :key="index"
            @click="changeSelectedLabel($event)"
          >
            {{ item3.name }}
          </li>
        </ul>
      </div>
      <van-loading size="39px" vertical type="spinner" v-if="!resultList.length"
        >加载中...</van-loading
      >
      <div class="list" v-else>
        <div
          class="item"
          v-for="result in resultList"
          :key="result.season_id"
          @click="gotoPassage(result.season_id)"
        >
          <div class="img">
            <!-- <img :src="result.vertical_cover" alt="" /> -->

            <van-image :src="result?.vertical_cover">
              <template v-slot:loading>
                <van-loading type="spinner" size="20" />
              </template>
            </van-image>
          </div>
          <h3>{{ result.title }}</h3>
          <div class="replace">
            <span class="topic"
              >更新至:&nbsp;第{{ result.last_ord }}话 &nbsp;{{
                result.bottom_info
              }}</span
            >
          </div>
        </div>
      </div>
    </div>
    <!-- <span class="search iconfont icon-sousuo"></span> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      sortList: [],
      resultList: [],
      selectedLabel: {
        styleId: -1,
        areaId: -1,
        isFinish: -1,
        order: 0,
        pageNum: 1,
        pageSize: 39,
        isFree: -1,
      },
    };
  },
  created() {
    //分类筛选条件
    this.axios.get("/AllLabel").then((res) => {
      // console.log(res);
      this.sortList = res.data.data;
      // console.log(this.sortList);
    });

    //筛选结果
    this.axios
      .get(
        "/ClassPage?styleId=-1&areaId=-1&isFinish=-1&order=0&pageNum=1&pageSize=39&isFree=-1"
      )
      .then((res) => {
        // console.log(res);
        this.resultList = res.data.data;
        // console.log(this.resultList);
      });
  },
  methods: {
    gotoPassage(comic_id) {
      this.$router.push({
        path: "/passage",
        query: {
          id: comic_id,
        },
      });
    },
    changeSelectedLabel(event) {
      console.log(event.target.dataset);
      // console.log();
      this.selectedLabel[event.target.dataset.key] = event.target.dataset.value;
      console.log(this.selectedLabel);
      this.resultList = [];
      this.axios
        .get(
          `/ClassPage?styleId=${this.selectedLabel.styleId}&areaId=${this.selectedLabel.areaId}&isFinish=${this.selectedLabel.isFinish}&order=0&pageNum=1&pageSize=39&isFree=-1`
        )
        .then((res) => {
          // console.log(res);
          this.resultList = res.data.data;
          // console.log(this.resultList);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.sort {
  margin-top: 50px;
  padding: 0px 12px;
  position: relative;
  .title {
    ul {
      display: flex;
      flex-wrap: wrap;
      margin-bottom: 3px;
      li {
        width: 50px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        font-size: 12px;
        color: #666;
        font-weight: 500;
        margin-bottom: 3px;
        margin-right: 10px;
        &.active {
          background-color: #fb7168;
          border-radius: 5px;
          color: #fff;
        }
        &:nth-child(6n) {
          margin-right: 0px;
        }
      }
    }
  }
  .list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding-bottom: 50px;
    .item {
      width: 30%;
      padding: 10px 0px;
      //   margin-right: 5px;
      .img {
        // width: 100%;
        height: 150px;
        border-radius: 5px;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      h3 {
        font-size: 14px;
        color: #333;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-weight: bold;
        height: 32px;
        line-height: 32px;
      }
      .replace {
        width: 100%;
        display: flex;
        color: #666;
        font-size: 12px;

        .topic {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
  .search {
    position: absolute;
    top: -35px;
    right: 20px;
    font-size: 20px;
    color: #000;
    font-weight: bold;
  }
   .van-loading--vertical {
    margin-top: 80px;
  }
}
</style>